//
//  outMoneyViewController.m
//  WZEfengAndEtong
//
//  Created by 李旭 on 16/9/23.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "outMoneyViewController.h"
#import "Masonry.h"
#import "CXmppRequestMgr.h"
#import "MBProgressHUD.h"
@interface outMoneyViewController ()
@property(nonatomic,weak)UILabel *blanceLable;
@property(nonatomic,weak)UITextField *moneyTextField;
@property(nonatomic,weak)UITextField *pwdTextField;
@property(nonatomic,weak)UIButton *outButton;
@end

@implementation outMoneyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setNewTitleCenter:@"取现"];
    self.view.backgroundColor = RGBCOLOR(243, 243, 243);
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self configInterFace];
}
-(void)configInterFace
{
    UILabel *headLabel = [[UILabel alloc]init];
    headLabel.text = @"您当前的余额";
    headLabel.font = [UIFont systemFontOfSize:13];
    headLabel.textColor = RGBCOLORWITH16COLOR(0x999999);
    headLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:headLabel];
    [headLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.width.mas_equalTo(100);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(30);
    }];
    UILabel *blanceLabel = [[UILabel alloc]init];
    blanceLabel.text =self.blance;
    blanceLabel.font = [UIFont systemFontOfSize:13];
    blanceLabel.textColor = [UIColor redColor];
    blanceLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:blanceLabel];
    self.blanceLable = blanceLabel;
    [blanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headLabel.mas_right).offset(0);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
        make.top.mas_equalTo(10);
    }];
    UILabel *unitLable = [[UILabel alloc]init];
    unitLable.text = @"元";
    unitLable.font = [UIFont systemFontOfSize:13];
    unitLable.textColor = RGBCOLORWITH16COLOR(0x999999);
    unitLable.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:unitLable];
    [unitLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.equalTo(blanceLabel.mas_right).offset(0);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(30);
    }];
    UIView *moneyView =[[UIView alloc]init];
    moneyView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:moneyView];
    [moneyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(blanceLabel.mas_bottom).offset(0);
        make.right.left.mas_equalTo(0);
        make.height.mas_equalTo(60);
    }];
    UIView *line0 = [[UIView alloc]init];
    line0.backgroundColor = RGBCOLORWITH16COLOR(0x999999);
    [moneyView addSubview:line0];
    [line0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];

    UIView *line = [[UIView alloc]init];
    line.backgroundColor = RGBCOLORWITH16COLOR(0x999999);
    [moneyView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    UITextField *moneyTextField = [[UITextField alloc]init];
    moneyTextField.placeholder = @"请输入提现金额";
    [moneyTextField addTarget:self action:@selector(checkmoney:) forControlEvents:UIControlEventEditingChanged];
    moneyTextField.keyboardType = UIKeyboardTypeDecimalPad;
    moneyTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    self.moneyTextField = moneyTextField;
    [moneyView addSubview:moneyTextField];
    [moneyTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(300);
        make.left.mas_equalTo(15);
    }];
    UILabel *yuanLabel = [[UILabel alloc]init];
    yuanLabel.text = @"元";
    yuanLabel.textColor = [UIColor blackColor];
    yuanLabel.textAlignment = NSTextAlignmentRight;
    [moneyView addSubview:yuanLabel];
    [yuanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(-10);
        make.width.mas_equalTo(40);
    }];
    
    
    
    UIView *pwdView =[[UIView alloc]init];
    pwdView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:pwdView];
    [pwdView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(moneyView.mas_bottom).offset(0);
        make.right.left.mas_equalTo(0);
        make.height.mas_equalTo(60);
    }];
    UIView *line1 = [[UIView alloc]init];
    line1.backgroundColor = RGBCOLORWITH16COLOR(0x999999);
    [pwdView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    UITextField *pwdTextField = [[UITextField alloc]init];
    self.pwdTextField = pwdTextField;
    pwdTextField.secureTextEntry = YES;
    pwdTextField.placeholder = @"请输入钱包密码";
    pwdTextField.keyboardType = UIKeyboardTypeDecimalPad;
    pwdTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    [pwdView addSubview:pwdTextField];
    [pwdTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(300);
        make.left.mas_equalTo(15);
    }];
    UIButton *outButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [outButton setBackgroundColor:RGBCOLOR(253, 156, 65)];
    [outButton setTitle:@"提现" forState:UIControlStateNormal];
    [outButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    outButton.titleLabel.font = [UIFont boldSystemFontOfSize:20];
    [outButton addTarget:self action:@selector(outMoney) forControlEvents:UIControlEventTouchUpInside];
    outButton.enabled = NO;
    outButton.layer.cornerRadius = 5;
    outButton.layer.masksToBounds = YES;
    self.outButton = outButton;
    [self.view addSubview:outButton];
    [outButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-30);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(self.view.width - 40);
        make.centerX.mas_equalTo(self.view);
    }];
}
-(void)checkmoney:(UITextField*)textField
{
    if ([self.moneyTextField.text doubleValue] > [self.blanceLable.text doubleValue]) {
        self.moneyTextField.textColor = [UIColor redColor];
        self.outButton.enabled = NO;
    }
    else
    {
        self.moneyTextField.textColor = [UIColor blackColor];
        self.outButton.enabled = YES;
    }
}
-(void)outMoney
{
    /*发网络请求 取现 cxmpprequest shareInstance*/
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
@end
